
#include "entry.h"

enum option{
    end,input_info,subject_avg,student_total_avg,student_rank_by_score,
    student_rank_by_no,student_rank_by_name,search_student_by_no,
    search_student_by_name,statistic,output_info
};

int main() {
    int student_count;
    int subject_count;
    printf("初始化：请输入学生数和课程数：");
    scanf("%d %d",&student_count,&subject_count);
    //分配内存
    pStudent students = calloc(student_count,sizeof(Student));
    for(int i=0;i<student_count;i++){
        students[i].name = calloc(100,sizeof(char));
        students[i].subjects = calloc(subject_count,sizeof(Subject));
    }

    int option = -1;
    while(option!=end) {
        switch (option) {
            case end:break;
            case input_info:{
//                inputInfo(students,student_count,subject_count);
                inputRandInfo(students,student_count,subject_count);
                break;
            }
            case subject_avg:{
                subject_average(students,student_count,subject_count);
                break;
            }
            case student_total_avg:{
                student_total_average(students,student_count,subject_count);
                break;
            }
            case student_rank_by_score:{
                student_rank_by_Score(students,student_count,subject_count);
                break;
            }
            case student_rank_by_no:{
                student_rank_by_No(students,student_count,subject_count);
                break;
            }
            case student_rank_by_name:{
                student_rank_by_Name(students,student_count,subject_count);
                break;
            }
            case search_student_by_no:{
                int number;
                printf("请输入学号：");
                scanf("%d",&number);
                search_student_byNo(students,student_count,subject_count,number);
                break;
            }
            case search_student_by_name:{
                char* name = calloc(100,sizeof(char));
                printf("请输入姓名：");
                scanf("%s",name);
                search_student_byName(students,student_count,subject_count,name);
                free(name);
                break;
            }
            case statistic:{
                statistic_(students,student_count,subject_count);
                break;
            }
            case output_info:{
                outputInfo(students,student_count,subject_count);
                break;
            }
            default:{
                printf("选项：\n\t1.输入学生学号姓名成绩\n\t2.计算每门课程平均分\n\t3.计算每个学生总分和平均分\n\t4.按总分高低输出名次表\n\t");
                printf("5.按学号由小到大输出名词表\n\t6.按名称字典序输出排序表\n\t7.按学号查询学生排名与成绩\n\t8.按姓名查询学生排名与成绩\n\t");
                printf("9.统计每门课程不同类别学生占比\n\t10.输出每个学生的学号，姓名，成绩\n\t0.退出\n");
            }
        }
        scanf("%d",&option);
    }

    //释放内存
    for(int i=0;i<student_count;i++){
        free(students[i].name);
        free(students[i].subjects);
    }
    free(students);
}
